import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/sys_state_main.dart';
import 'package:flutter_eve_plugin/components/health/weight_details.dart';
import 'package:flutter_eve_plugin/components/main/empty_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_ability_details.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_qjs_form.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_upgrade.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_pass_rank.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_rank.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_start_game.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_succ.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_area_code_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_binding_succ_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_birthday_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_boot_machine_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_connect_net_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_input_wifi_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_select_machine_page.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/login_select_role_page.dart';
import 'package:flutter_eve_plugin/pages/debug/main.dart';
import 'package:flutter_eve_plugin/pages/health/main.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/archives/main.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/checkpoint/main.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/login/main.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/rank/main.dart';

GlobalKey<NavigatorState> navigatorKey = GlobalKey();
String initPushName = RouteConstant.EmptyPage;

///路由表url名称
class RouteConstant {
  static const String EmptyPage = '/';
  static const String DebugMainPage = '/debug';
  static const String HealthMainPage = '/health';
  static const String SysStateMainPage = '/health/sysState';
  static const String WeightDetailsPage = '/health/weight';
  static const String LoginMainPage = '/login';
  static const String LoginAreaCodePage = '/login/areaCode';
  static const String LoginBirthdayPage = '/login/birthday';
  static const String LoginSelectMachinePage = '/login/selectMachine';
  static const String LoginBootMachinePage = '/login/bootMachine';
  static const String LoginInputWIFIPage = '/login/inputWIFI';
  static const String LoginConnectNetPage = '/login/connectNet';
  static const String LoginBindingSUCCPage = '/login/bindingSUCC';
  static const String LoginSelectRolePage = '/login/selectRole';
  static const String RankListMainPage = '/yx/rank';
  static const String CheckpointMainPage = '/yx/checkpoint';
  static const String CheckpointRankPage = '/yx/checkpoint/checkpointRank';
  static const String CheckpointPassRankPage = '/yx/checkpoint/passRank';
  static const String CheckpointPrepareGamePage = '/yx/checkpoint/prepareGame';
  static const String CheckpointStartGamePage = '/yx/checkpoint/startGame';
  static const String CheckpointSuccPage = '/yx/checkpoint/succ';
  static const String ArchivesMainPage = '/yx/archives';
  static const String ArchivesUpgradePage = '/yx/archives/upgrade';
  static const String ArchivesQJSFormPage = '/yx/archives/qjsForm';
  static const String ArchivesAbilityDetailsPage = '/yx/archives/abilityDetails';
  static const String MemoryHomePage = '/yx/memory';
}

///通过 routeName名称 返回 Widget的名称
String routeWidgetName(String routeName) {
  var defaultRouteName = 'EmptyPage';
  var map = {
    RouteConstant.EmptyPage: 'EmptyPage',
    RouteConstant.DebugMainPage: 'DebugMainPage',
    RouteConstant.HealthMainPage: 'HealthMainPage',
    RouteConstant.SysStateMainPage: 'SysStateMainPage',
    RouteConstant.WeightDetailsPage: 'WeightDetailsPage',
    RouteConstant.LoginMainPage: 'LoginMainPage',
    RouteConstant.LoginAreaCodePage: 'LoginAreaCodePage',
    RouteConstant.LoginBirthdayPage: 'LoginBirthdayPage',
    RouteConstant.LoginSelectMachinePage: 'LoginSelectMachinePage',
    RouteConstant.LoginBootMachinePage: 'LoginBootMachinePage',
    RouteConstant.LoginInputWIFIPage: 'LoginInputWIFIPage',
    RouteConstant.LoginConnectNetPage: 'LoginConnectNetPage',
    RouteConstant.LoginBindingSUCCPage: 'LoginBindingSUCCPage',
    RouteConstant.LoginSelectRolePage: 'LoginSelectRolePage',
    RouteConstant.RankListMainPage: 'RankListMainPage',
    RouteConstant.CheckpointMainPage: 'CheckpointMainPage',
    RouteConstant.CheckpointRankPage: 'CheckpointRankPage',
    RouteConstant.CheckpointPassRankPage: 'CheckpointPassRankPage',
    RouteConstant.CheckpointPrepareGamePage: 'CheckpointPrepareGamePage',
    RouteConstant.CheckpointStartGamePage: 'CheckpointStartGamePage',
    RouteConstant.CheckpointSuccPage: 'CheckpointSuccPage',
    RouteConstant.ArchivesMainPage: 'ArchivesMainPage',
    RouteConstant.ArchivesUpgradePage: 'ArchivesUpgradePage',
    RouteConstant.ArchivesQJSFormPage: 'ArchivesQJSFormPage',
    RouteConstant.ArchivesAbilityDetailsPage: 'ArchivesAbilityDetailsPage',
    RouteConstant.MemoryHomePage: 'MemoryHomePage',
  };
  return map.containsKey(routeName) ? map[routeName] : defaultRouteName;
}

///路由表  部分title不是页面需要，但是必填是为了直观查看
Map<String, WidgetBuilder> routes(BuildContext context) {
  return {
    RouteConstant.EmptyPage: (context) => EmptyPage(title: 'flutter初始界面'),
    RouteConstant.DebugMainPage: (context) => DebugMainPage(title: 'debug-route'),
    RouteConstant.HealthMainPage: (context) => HealthMainPage(title: '琥珀的健康'),
    RouteConstant.SysStateMainPage: (context) => SysStateMainPage(title: '各系统健康状况'),
    RouteConstant.WeightDetailsPage: (context) => WeightDetailsPage(title: '琥珀的体重'),
    RouteConstant.LoginMainPage: (context) => LoginMainPage(title: '登录'),
    RouteConstant.LoginAreaCodePage: (context) => LoginAreaCodePage(title: '请选择国家和地区'),
    RouteConstant.LoginBirthdayPage: (context) => LoginBirthdayPage(title: '选择生日'),
    RouteConstant.LoginSelectMachinePage: (context) => LoginSelectMachinePage(title: '是否有机器'),
    RouteConstant.LoginBootMachinePage: (context) => LoginBootMachinePage(title: '机器开机'),
    RouteConstant.LoginInputWIFIPage: (context) => LoginInputWIFIPage(title: '输入WIFI'),
    RouteConstant.LoginConnectNetPage: (context) => LoginConnectNetPage(title: '扫码联网'),
    RouteConstant.LoginBindingSUCCPage: (context) => LoginBindingSUCCPage(title: '绑定成功'),
    RouteConstant.LoginSelectRolePage: (context) => LoginSelectRolePage(title: '选择角色'),
    RouteConstant.RankListMainPage: (context) => RankListMainPage(title: '大神榜'),
    RouteConstant.CheckpointMainPage: (context) => CheckpointMainPage(title: '副本'),
    RouteConstant.CheckpointRankPage: (context) => CheckpointRankPage(title: '副本详情'),
    RouteConstant.CheckpointPassRankPage: (context) => CheckpointPassRankPage(title: '通关排名'),
    RouteConstant.CheckpointPrepareGamePage: (context) => CheckpointPrepareGamePage(title: '准备比赛'),
    RouteConstant.CheckpointStartGamePage: (context) => CheckpointStartGamePage(title: '开始比赛'),
    RouteConstant.CheckpointSuccPage: (context) => CheckpointSuccPage(title: '副本通关'),
    RouteConstant.ArchivesMainPage: (context) => ArchivesMainPage(title: '档案'),
    RouteConstant.ArchivesUpgradePage: (context) => ArchivesUpgradePage(title: '升级进阶'),
    RouteConstant.ArchivesQJSFormPage: (context) => ArchivesQJSFormPage(title: '千机伞形态'),
    RouteConstant.ArchivesAbilityDetailsPage: (context) => ArchivesAbilityDetailsPage(title: '能力详情'),
  };
}

///通过routeName 返回Widget
Widget findRouteWidget(BuildContext context, String name) {
  var map = routes(context);
  return map.containsKey(name) ? map[name](context) : map[RouteConstant.EmptyPage](context);
}
